﻿using System.Web.Mvc;
using Dentiste.Domain;
using Dentiste.Domain.Factories;
using Dentiste.Domain.Interfaces;

namespace Dentiste.UI.Controllers
{
    public class InamiManagerController : Controller
    {
        //
        // GET: /InamiManager/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Add()
        {
            return View();
        }

        [HttpPost]
        public void Add(string code, string label, int prix1, int prix2, int prix3)
        {
            IInami i = new Factory<IInami>().Create();
            i.Code = code;
            i.Label = label;
            i.Prix1 = prix1;
            i.Prix2 = prix2;
            i.Prix3 = prix3;
            DentisteManager.Instance.InsertInami(i);
        }

        public ActionResult Edit()
        {
            IInami model = null;
            if (!string.IsNullOrEmpty(RouteData.Values["id"] as string))
            {
                var id = RouteData.Values["id"] as string;
                model = DentisteManager.Instance.SelectInami(id);
            }
            return View(model);
        }

        [HttpPost]
        public void Edit(string code, string label, int prix1, int prix2, int prix3)
        {
            IInami inami = DentisteManager.Instance.SelectInami(code);
            if (inami == null)
                return;
            inami.Label = label;
            inami.Prix1 = prix1;
            inami.Prix2 = prix2;
            inami.Prix3 = prix3;
            DentisteManager.Instance.UpdateInami(inami);
        }

        public ActionResult Delete()
        {
            return View();
        }

        [HttpPost]
        public void Delete(string code)
        {
            IInami inami = DentisteManager.Instance.SelectInami(code);
            if (inami == null)
                return;
            DentisteManager.Instance.DeleteInami(inami);
        }

        [HttpPost]
        public void Link(string parentId, string childId)
        {
            IInami parent = DentisteManager.Instance.SelectInami(parentId);
            IInami child = DentisteManager.Instance.SelectInami(childId);
            DentisteManager.Instance.Link(parent, child);
        }

        [HttpPost]
        public void Unlink(string parentId, string childId)
        {
            IInami parent = DentisteManager.Instance.SelectInami(parentId);
            IInami child = DentisteManager.Instance.SelectInami(childId);
            DentisteManager.Instance.Unlink(parent, child);
        }
    }
}